package com.hgw.Demo06_Singleton.type6;

/**
 * Data time:2021/12/11 13:28
 * StudentID:2019112118
 * Author:hgw
 * Description: 静态内部类单例模式
 */
public class SingletonTest06 {

    public static void main(String[] args) {
        Singleton instance1 = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance1==instance2);
    }

}

// 静态内部类
class Singleton {

    // 构造器私有化
    private Singleton(){}

    // 写一个静态内部类 ， 该类中有一个静态属性 Singleton
    private static class SingletonInstance {
        private static final Singleton INSTNCE = new Singleton();
    }

    // 提供一个静态的公有方法，直接返回 SingletonInstance.INSTNCE;
    public static Singleton getInstance() {
        return SingletonInstance.INSTNCE;
    }
}